package com.example.qxfw.ldyj.controller;

import cn.hutool.core.io.unit.DataUnit;
import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.qx.Raiden;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.ldyj.service.JckbService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.util.List;

@Api(tags = "雷电气象--监测快报")
@RestController
@CrossOrigin
@RequestMapping("/jckb")
public class JckbController {
    @Autowired
    private JckbService jckbService;
    @ApiOperation("根据时间段查询闪电定位仪监测记录临时表")
    @GetMapping("/SelectByTimePeriodOfRaiden")
    public SysResult SelectByTimePeriodOfRaiden(
            String dateStart, String dateEnd, String timeStart, String timeEnd
    ){
        StringBuilder builder1 = new StringBuilder();
        builder1.append(dateStart);
        builder1.append(" ");
        builder1.append(timeStart);
        StringBuilder builder2 = new StringBuilder();
        builder2.append(dateEnd);
        builder2.append(" ");
        builder2.append(timeEnd);
        Timestamp forecasttimeStart = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(builder1.toString()));
        Timestamp forecasttimeEnd = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(builder2.toString()));
        List<Raiden> list = jckbService.SelectByTimePeriodOfRaiden(forecasttimeStart, forecasttimeEnd);
        return SysResult.success(list);
    }
    @ApiOperation("气象信息-雷电信息-获取早晚时间")
    @GetMapping("/getEarliestTime")
    public SysResult getEarliestTime(){
       String earliestTime = jckbService.getEarliestTime();
        String latestTime = jckbService.getLatestTime();
       return SysResult.success(earliestTime,latestTime);
    }

}
